<template>
<div>
  <el-table
    :data="tableData"
    style="width: 100%">
    <el-table-column label="ID" width="180" prop="id" />
    <el-table-column label="姓名" width="180" prop="username" />
    <el-table-column label="昵称" width="180" prop="nickname" />
    <el-table-column label="头像" width="180" >
      <template slot-scope="scope">
         <div style="width: 50px; height: 50px;">
           <!-- {{}} -->
           <img style="width: 100%;height: 100%" :src="scope.row.avatar" alt="">
          </div>
      </template>
    </el-table-column>
    <el-table-column label="时间" width="180" prop="createTime" />

    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
   <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[5, 10, 20, 30]"
      :current-page="currentPage"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
</div>




</template>
<script>
import {
  FetchQueryUsers,
} from '../../api'
  export default {
    data() {
      return {
        tableData: [],
        total: 0,
        currentPage: 1,
        size: 5
      }
    },
    watch: {
      // currentPage(v) {
      //   console.log('v....:', v)
      // },
      // size(v) {
      //   console.log('sieze.....', v)
      // }
    },
    mounted() {
      this.getData({})
    },
    methods: {
      // async getData() {
      //   const data = await FetchQueryUsers()
      // },
      getData({page=0, size = this.size}) {
        FetchQueryUsers({ page, size}).then(res => {
          this.tableData = res.data.data
          this.total = res.data.total
          console.log('res: ....:', this.tableData)
        })
      },
      // 监听每页切换的条数
      handleSizeChange(val) {
        this.size = val;
        console.log(`每页 ${val} 条`);
        this.getData({size:this.size})
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val-1}`);
        // 对当前的页码赋值
        this.currentPage = val;
        this.getData({page: val - 1})
      },
      handleEdit(index, row) {
        console.log(index, row);
      },
      handleDelete(index, row) {
        console.log(index, row);
      }
    }
  }
</script>